<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
    <head th:replace="/common/include :: header(~{::title}, ~{::link}, ~{::style})">
        <title>系统管理-参数管理-编辑</title>
    </head>
    <body class="white-bg">
        <form class="form-horizontal m" id="form-config-edit">
            <div class="animated fadeInRight form-content">
                <input type="hidden" id="configId" name="configId"/>
                <div class="form-group">
                    <label class="col-xs-3 control-label">参数名称：</label>
                    <div class="col-xs-8">
                        <input class="form-control" type="text" name="configName" id="configName"/>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-3 control-label">参数键名：</label>
                    <div class="col-xs-8">
                        <input class="form-control" type="text" name="configKey" id="configKey"/>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-3 control-label">参数键值：</label>
                    <div class="col-xs-8">
                        <textarea class="form-control" rows="5" name="configValue" id="configValue" ></textarea>
                    </div>
                </div>
                <div class="form-group mb40">
                    <label class="col-xs-3 control-label">系统内置：</label>
                    <div class="col-xs-8">
                        <div class="radio-box" th:each="dict : ${@dict.getDataGroup('sys_yes_no_char')}">
                            <input type="radio" th:id="${dict.dictLabel + dict.dictValue}" name="configType" th:value="${dict.dictValue}" default-value="Y"/>
                            <label th:for="${dict.dictLabel + dict.dictValue}" th:text="${dict.dictLabel}"></label>
                        </div>
                    </div>
                </div>
            </div>

            <div class="form-footer sticky" th:classappend="${@config.hasPermission('tool:config:edit')}">
                <button class="btn btn-success form-submit" type="button" onclick="save()">保存</button>
                <button class="btn btn-default" type="button" onclick="closeWin()">关闭</button>
            </div>
        </form>

        <div th:replace="/common/include :: footer"></div>

        <script th:inline="javascript">
            var config_id = [[${id}]];
            var layer_index = [[${layer_index}]];
            var layer_callback = [[${layer_callback}]];
            var permitted = [[${@config.isPermittedOperator('system:config:add')}]];
            var prefix = ctx + 'api/system/config';

            $(function () {
                // 表单赋值
                $.operate.get({
                    url: prefix + '/load',
                    data: {
                        'id': config_id
                    },
                    success: function(result) {
                        if (result.code === 200) {
                            $.form.load('form-config-edit', result.param, !permitted);
                            $.form.initValidatorRemote('form-config-edit', 'tb_sys_config');
                        } else {
                            $.modal.toast.error(result.msg, result.param);
                            setTimeout(function() {
                                window.location.href = ctx + 'error/' + result.code;
                            }, 1500);
                        }
                    },
                    error: function(result) {
                        window.location.href = ctx + 'error/500';
                    }
                });
            });

            function save() {
                if ($.form.isValid('form-config-edit')) {
                    // 加载参数数据
                    var param = $.form.serialize('form-config-edit');
                    $.operate.post({
                        url: prefix + '/save',
                        data: param
                    }, true, layer_index, layer_callback);
                }
            }

            function closeWin() {
                $.modal.lay.close();
            }
        </script>
    </body>
</html>
